<template>
  <div>
    <el-container>
      <el-header>
        <div class="logo-box">
          <img src="../assets/heima.png" alt />
          <span>电商后台管理系统</span>
        </div>
        <el-button type="info" @click="logout()">退出</el-button>
      </el-header>
      <el-container>
        <el-aside width="200px">
          <div
            style="width:200px;"
            class="toggle_bar"
            @clicl="menshow != menshow"
            id="toggle_bar"
          >
            |||
          </div>
          <el-menu
            background-color="#333744"
            text-color="#fff"
            active-text-color="#409EFF"
            unique-opened
            collapse="menushow"
            :collapse-transition="false"
          >
            <el-submenu
              :index="item.id + ''"
              :style="{ width: showmenu ? '65px' : '200px' }"
              v-for="item in menuList"
              :key="item.id"
            >
              <template slot="title">
                <i :class="'iconfont icon-' + icons['ic' + item.id]"></i>
                <span>{{ item.authName }}</span>
              </template>
              <el-menu-item
                :index="item.id + '-' + item2.id"
                v-for="item2 in item.children"
                :key="item2.id"
                ><template slot="title">
                  <i class="el-icon-location"></i>
                  <span>{{ item.authName }}</span>
                </template></el-menu-item
              >
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <!-- 为第3级别业务组件的显示设置占位符 -->
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  created() {
    this.getMenuList();
  },
  methods: {
    async getMenuList() {
      var { data: dt } = await this.$http.get("/menus");
      if (dt.meta.status !== 200) {
        return this.$message.error(dt.msg);
      }
      this.menuList = dt.data;
    },
    logout() {
      this.$confirm("确认要退出系统么？", "退出", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          window.sessionStorage.removeItem("token");
          this.$router.push("/login");
        })
        .catch(() => {});
    }
  },
  data() {
    return {
      menshow: false,
      menuList: [],
      icons: {
        ic125: "users",
        ic103: "tijikongjian",
        ic101: "shangpin",
        ic102: "danju",
        ic145: "baobiao"
      }
    };
  }
};
</script>

<style lang="less" scoped>
.el-container {
  height: 100%;
  .el-header {
    background-color: #373d41;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-right: 20px;
    .logo-box {
      display: flex;
      font-size: 22px;
      color: #fff;
      align-items: center;
      user-select: none;
      img {
        width: 50px;
        height: 50px;
        margin-right: 10px;
      }
    }
  }
  .el-aside {
    background-color: #333744;
    #toggle_bar {
      background-color: #4a5064;
      text-aligin: center;
      color: #fff;
      height: 25px;
      line-height: 25px;
      font-size: 12px;
      letter-spacing: 0.1em;
      user-select: none;
      cursor: pointer;
    }
  }
  .el-main {
    background-color: #eaedf1;
  }
}
</style>
